package com.example.demo.controller;

import com.example.demo.common.entity.ParamBase;
import com.example.demo.common.entity.ParamPage;
import com.example.demo.common.util.BucnInvoker;
import com.example.demo.common.util.ListResult;
import com.example.demo.common.util.OptResult;
import com.example.demo.service.DictionaryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@Api(tags = "*字典管理", value = "字典", description = "字典")
@RestController
@RequestMapping("/ly/mp/clue/dic")
public class DictionaryController {

    @Autowired
    DictionaryService dictionaryService;

    @ApiOperation("增加编辑")
    @PostMapping("dicsave.do")
    public OptResult userSave(@RequestBody ParamBase<Map<String, Object>> paramBase,
                              @RequestHeader(HttpHeaders.AUTHORIZATION) String token) {
        return BucnInvoker.doOpt(() -> dictionaryService.save(paramBase, token));
    }

    @ApiOperation("删除")
    @PostMapping("dicdel.do")
    public OptResult dicDel(@RequestBody ParamBase<Map<String, Object>> paramBase,
                            @RequestHeader(HttpHeaders.AUTHORIZATION) String token) {
        return BucnInvoker.doOpt(() -> dictionaryService.delete(paramBase, token));
    }


//    @ResponseExcel(exportDataLocation = "root.rows")
    @ApiOperation("查询")
    @PostMapping("dicpage.do")
    public ListResult<Map<String, Object>> dicPage(@RequestBody ParamPage<Map<String, Object>> paramPage,
                                                   @RequestHeader(HttpHeaders.AUTHORIZATION) String token) {
        return BucnInvoker.doList(() -> dictionaryService.page(paramPage));
    }


    @ApiOperation("查询字典类别")
    @PostMapping("dicfindtype.do")
    public ListResult<Map<String, Object>> dicFindType(@RequestBody ParamPage<Map<String, Object>> paramPage,
                                                       @RequestHeader(HttpHeaders.AUTHORIZATION) String token) {
        return BucnInvoker.doList(() -> dictionaryService.typePage(paramPage));
    }


}

